package topcoder;

import java.util.HashMap;
import java.util.HashSet;

public class EelAndRabbit {
	
	
	
	int getmax(int[] l, int[] t) {
		
		int N = l.length;
		
		HashMap<Integer, HashSet<Integer>> G = new HashMap<Integer, HashSet<Integer>>();
		for (int i = 0; i < N - 1; i++) {
			for (int j = i+1; j < N; j++) {
				if ( (t[i] >= t[j] && t[i] <= t[j] + l[j]) || (t[i] + l[i] >= t[j] && t[i] + l[i] <= t[j] + l[j]) ) {
					if (!G.containsKey(i))
						G.put(i, new HashSet<Integer>());
					if(!G.containsKey(j))
						G.put(j, new HashSet<Integer>());
					G.get(i).add(j);
					G.get(j).add(i);
				}
			}
		}
		
		int max = 0;
		int maxi = -1;
		for (int i : G.keySet()) {
			if (G.get(i).size() > max){
				max = G.get(i).size();
				maxi = i;
			}
		}
		
		int r = max + 1;
		HashSet<Integer> D = new HashSet<Integer>();
		D.add(maxi);
		D.addAll(G.get(maxi));
		
		G = new HashMap<Integer, HashSet<Integer>>();
		for (int i = 0; i < N - 1; i++) {
			if (D.contains(i)) continue;
			for (int j = i+1; j < N; j++) {
				if (D.contains(j)) continue;
				if ( (t[i] >= t[j] && t[i] <= t[j] + l[j]) || (t[i] + l[i] >= t[j] && t[i] + l[i] <= t[j] + l[j]) ) {
					if (!G.containsKey(i))
						G.put(i, new HashSet<Integer>());
					if(!G.containsKey(j))
						G.put(j, new HashSet<Integer>());
					G.get(i).add(j);
					G.get(j).add(i);
				}
			}
		}
		
		
		max = 0;
		for (int i : G.keySet()) {
			if (G.get(i).size() > max){
				max = G.get(i).size();
			}
		}
		
		return r + max + 1;
		
	}
	
	public static void main(String[] args) {
		EelAndRabbit r = new EelAndRabbit();
		System.out.println(r.getmax(new int[]{2, 4, 3, 2, 2, 1, 10}, new int[]{2, 6, 3, 7, 0, 2, 0}));
	}
}
